<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta name="format-detection" content="telephone=no, address=no, email=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="misapplication-tap-highlight" content="no" />
		<meta name="HandheldFriendly" content="true" />
		<link rel="stylesheet" href="../../css/mui.min.css" type="text/css" charset="utf-8" />
		<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
		<link rel="stylesheet" href="../../css/product.css" type="text/css" charset="utf-8" />
		<style>
			.productFile {
				padding: 0.33rem;
				background: #fff;
			}
			.productFile p {
				color: #666;
				margin-bottom: 0.42rem;
			}
		</style>
	</head>
	<body>
		<div class="mui-content" style="padding:0.24rem 0.24rem 0 0.24rem">
			<div>
				<div>
					<p>个人信息</p>
					<div class="productFile">
						<span style="float:right;color:#F00" id="nextStepHtml"></span>
						<div class="file1" id="file1">

						</div>

					</div>
					<div class="historyList">
						<p>历史记录</p>
						<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
				<div class="mui-scroll">
					<!--数据列表-->
					<ul class="mui-table-view mui-table-view-chevron  historyUi"  style="margin:0px;">
						
					</ul>
				</div>
			</div>
			 
					</div>
				</div>
			</div>
		</div>
		
		<div class="none" id='stopQudao' style="border: none; background: transparent;text-align: center;">
			<button type="button" class="mui-btn mui-btn-primary mui-btn-full" id="nextStep" style="width: 48%;height:44px;background:#f1c40f;color:#fff;border-color:#f1c40f">暂停该渠道</button>
		</div>
		<script src="../../js/resize.js"></script>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/ajaxFun.js"></script>
		<script src="../../js/dialog.js"></script>
	 
	 <script>
	 	var data = {
			pageNo: 1,
			pageSize: 10,
			traderId: '',
			productNo:'',
		};
		var stopQudao = document.getElementById("stopQudao");
		var currentView,parseData,flag;
		var table = document.body.querySelector('.historyUi');
		var status;
		 
		window.addEventListener('reloadChild', function(event) {
			var a=plus.webview.getWebviewById('jxsdialog');
			if(a){
				a.close();
			}
			currentView.reload();
		});
		
		
		(function($, doc) {
			$.plusReady(function() {
				currentView = plus.webview.currentWebview();
				parseData = currentView.parseData;
				flag=currentView.flag;				
				mui.init({
					pullRefresh: {
						container: '#pullrefresh',
						down: {
							 callback: pulldownRefresh
						},
						up: { 
							contentrefresh: '正在加载...',
							callback: pullupRefresh
						}
					}
				});
				if(!parseData.id) {
					plus.nativeUI.alert('请选择要查看的经销商');
					return false;
				}
				
				formPersonInfo(); //获取用户信息
				
				
				data.traderId = parseData.id;
				data.productNo = parseData.productNo;

				/*停用、启用经销商*/
				stopQudao.addEventListener('tap', function() {
					var aa=plus.webview.create('dialog.html','jxsdialog',{background:'transparent',zindex:'100',top:'40%'},{parseData:parseData,status:status});
					aa.show();
					var detailPage = plus.webview.getWebviewById('jxsInfo');
					detailPage.setStyle({mask:"rgba(0,0,0,0.5)"});
				})
			})
		}(mui, document))
		
		if (mui.os.plus) {
				mui.plusReady(function() {
					setTimeout(function() {
						mui('#pullrefresh').pullRefresh().pullupLoading();
					}, 100);

				});
			} else {
				mui.ready(function() {
					mui('#pullrefresh').pullRefresh().pullupLoading();
				});
			}
			
			//下拉刷新
			function pulldownRefresh() {
				mui('#pullrefresh').pullRefresh().scrollTo(0,0,100);
				var url = baseUrl + 'outScan/get/trader/history.do';
				data.pageNo=1;table.innerHTML='';
				mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
				mui('#pullrefresh').pullRefresh().refresh(true);
				ajaxFun.postFun(url,data,'',formList);	
			}
			
			
		function pullupRefresh() {
			setTimeout(function() {
				var url = baseUrl + 'outScan/get/trader/history.do';
				ajaxFun.postFun(url,data,'',formList);	
			},100);
		}
		
		function fromPinfoHtml(datainfo) {
			var temp = datainfo.data;
			if(!temp) {
				return '<p style="margin-bottom:0;">该经销商暂时没有信息</p>';
			}
			var html = '<p>角色：经销商</p> <p>姓名： ' + temp.name + ' </p> <p> 电话： ' + temp.mobile + ' </p> <p> 公司： ' + temp.companyName + ' </p> <p> 地址： ' + temp.address + ' </p>';
			return html;
		}

	 
		var total = 0;
		function formList(datalist, params) {
			list = datalist.data.dataList ? datalist.data.dataList : [];
			setTimeout(function() {
				data.pageNo++;
				if(list.length > 0) {
					for(var i = 0, len = list.length; i < len; i++) {
						var temp = list[i];
						var li = document.createElement('li');
						li.className = 'historyItem';
						if(data.pageNo == 1 && i == 0) {
							li.className = 'historyItem';
						}
						var html = '';
						var isOutStr = temp.isOut == 1 ? '发去' : temp.isOut == 2 ? '发来' : '未知';
						html += '<p class="opeate">' + isOutStr + '</p>' +
							'<p>操作时间：' + temp.updateTime + '</p>' +
							'<p>操作数量：' + temp.count + '</p>';
						li.innerHTML = html;
						table.appendChild(li);
						mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
						var liLen = document.querySelectorAll('.historyItem').length;
						total = datalist.data.total >= 0 ? datalist.data.total : total;
						if(liLen >= total) {
							mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //参数为true代表没有更多数据了。
						} else {
							mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
						}
					}
				} else {
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
				}

			})
		}
		
		
		function formPersonInfo(){
			/*获取个人信息*/
				var url = baseUrl + 'dealersController/get/trader/by/id.do';
				ajaxFun.postFun(url, parseData, '', function(datainfo) {
					/*获取下级经销商信息的时候，更新parseData添加status状态*/
					if(parseData.type == 1) {
						parseData = ajaxFun.extend({}, parseData, {
							status: datainfo.data.status == 1 ? 0 : 1,
							id: datainfo.data.id
						})
						if(datainfo.data.status == 1 || datainfo.data.status == 0) {
							if(datainfo.data.status == 0) {
								document.getElementById("nextStep").innerHTML = '重新启用该渠道';
								document.getElementById("nextStepHtml").innerHTML = '已暂停';
								status=0;
							}else{
								document.getElementById("nextStepHtml").innerHTML = '';
								status=1;
							}
							document.getElementById("stopQudao").style.display = 'block';
						} 
					}
					var html = fromPinfoHtml(datainfo); //创建经销商信息的html
					document.getElementById("file1").innerHTML = html;
				})
		}
	 </script>
	</body>
</html>
